package com.hdu.metrics_center.redisCommand;

import com.hdu.metrics_center.enums.RedisCommandType;
import com.hdu.metrics_center.metrics.MetricsExecuteReq;
import com.hdu.metrics_center.metrics.MetricsExecuteResult;
import com.hdu.metrics_center.utils.JedisUtils;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;


@Component
public class HDelRedisCommand implements RedisCommand {
    @Override
    public RedisCommandType support() {
        return RedisCommandType.HDEL;
    }

    @Override
    public MetricsExecuteResult operate(MetricsExecuteReq metricsExecuteReq) {
        Jedis jedis = JedisUtils.getJedis();
        jedis.hdel(metricsExecuteReq.getKey(), metricsExecuteReq.getField());
        return MetricsExecuteResult
                .builder()
                .reqUuid(metricsExecuteReq.getReqUuid())
                .type(null)
                .value(null)
                .build();
    }
}
